package com.ants.boot.system.controller;

import com.ants.boot.core.Response;
import com.ants.boot.core.annotation.Log;
import com.ants.boot.model.BaseController;
import com.ants.boot.system.domain.OperateLog;
import com.ants.boot.system.dto.operatelog.DelLogDto;
import com.ants.boot.system.dto.operatelog.QueryOperateLogDto;
import com.ants.boot.system.service.OperateLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 蚂蚁会花呗
 * @date 2022/3/21 15:59
 */
@RestController
@RequestMapping("system/operate_log")
@Api(tags = "日志管理")
public class OperateLogController extends BaseController {

    @Autowired
    private OperateLogService operateLogService;

    /**
     * 日志分页
     * @param dto
     * @return
     */
    @PostMapping("page_info")
    @Log(module = "日志管理",operate = "查询、搜索")
    @ApiOperation(value = "日志分页",notes = "日志查询搜索")
    public Response pageInfo(@RequestBody @Validated QueryOperateLogDto dto){
        IPage<OperateLog> iPage = operateLogService.pageInfo(dto);
        return Response.okData(iPage);
    }

    /**
     * 删除和批量删除
     * @param dto
     * @return
     */
    @PostMapping("del_log")
    @Log(module = "日志管理",operate = "删除日志")
    @ApiOperation(value = "删除日志",notes = "删除日志")
    public Response delLog(@RequestBody @Validated DelLogDto dto){
        boolean result = operateLogService.delLog(dto.getIds());
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

}
